package com.terminee.behaviors;

import java.util.List;
import java.util.Map;

import javax.jdo.Query;

import com.terminee.model.Term;

public class TermWordBehavior extends TermBehavior {

	@Override
	public Object read(Object value, List<String> properties) {
		String word;
        if (value instanceof String) {
            word = (String) value;
            if (word.isEmpty()) {
                throw new IllegalArgumentException("Search string cannot be empty");
            }
        } else {
            throw new IllegalArgumentException("Search value must be a String");
        }

        Query query = pm.newQuery(Term.class);
        query.setFilter("word == wordParam");
        query.declareParameters("String wordParam");

        // get results
        try {
            return query.execute(word);
            /*List<Object> objectsToDetach = new ArrayList<Object>(objects);
            for (Object object : objects) {
                Buzzword buzzword = (Buzzword) object;

                if (properties.contains(Buzzword.BUZZWORD_LOCALES)) {
                    buzzword.getLocales();
                }
            }
            pm.detachCopyAll(objectsToDetach);*/
            //return terms;
        } finally {
            query.closeAll();
        }
	}

	@Override
	public List<Object> excute(String filter, String declareParameters, Map<String, Object> parameters,
			List<String> properties) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

}
